package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
@Slf4j
@RequiredArgsConstructor
public class ShopController {

    public static final String  KEY = "SHOP_STATUS";
    private final RedisTemplate redisTemplate;
//    @PutMapping("/{status}")
//    @ApiOperation("修改店铺状态")
//    public Result setStatus(@PathVariable Integer status){
//        log.info("(第四章 云岚宗)修改店铺状态:{}",status==1?"开启":"关闭");
//        redisTemplate.opsForValue().set("SHOP_STATUS",status);
//        return Result.success();
//    }

    @GetMapping("/status")
    @ApiOperation("获取店铺状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
        log.info("(第五章 聚气散)获取店铺状态:{}",status==1?"营业":"关门");
        return Result.success(status);
    }
}
